#ifndef SEARCH_H
#define SEARCH_H

#include "board.h"
#include "evaluater.h"
#include "movegenerator.h"
#include "movemaker.h"

class Search
{
public:
    // constructor
    // - set reference to board
    Search(Board & board)
        : board_(board), evaluater_(board), moveGenerator_(board), moveMaker_(board, moveGenerator_)
    {
        qDebug() << "Search object created";

    }

    void init();
    void setSearchDepth(size_t);
    void setStartSideToMove(bool);
    size_t getSearchDepth();
    MoveMaker getMoveMaker();

    // search algorithms
    // - negamax with alpha-beta pruning
    int negaMax(int, int, int);
    int chooseRandomMove();
    U64 perft(int, int);

    // thinking
    void doThink();

    //bool isOwnKingAttacked();
    bool isOtherKingAttacked();

    // best move line found in search
    std::vector<Move> currentBestMoveLine;
    std::vector<Move> finalBestMoveLine;

    // count nodes
    unsigned long nodeCounter;
    // count alpha-beta cutOffs
    unsigned long alphaBetaCutOffs;
    // depth of search
    size_t searchDepth_;
    bool startSideToMove_;

    // debug
    void DebugInit();
    void DebugCheck(Move);
    // debug status and flags of the board before and after do/undo a move
    U64 dWK, dWQ, dWR, dWB, dWN, dWP,dBK, dBQ, dBR, dBB, dBN, dBP;
    int ePS;
    bool wCC00;
    bool wCC000;
    bool bCC00;
    bool bCC000;

private:
    Board & board_;
    Evaluater evaluater_;
    MoveGenerator moveGenerator_;
    MoveMaker moveMaker_;
};
#endif // SEARCH_H
